//
//  ZGSmsgCommentListCell.m
//  MapleLeaf
//
//  Created by 邝子涵 on 15/12/3.
//  Copyright © 2015年 AntennaBabyTeam. All rights reserved.
//

#import "ZGSmsgCommentListCell.h"

@implementation ZGSmsgCommentListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.iconImageView = [[UIImageView alloc] init];
    self.iconImageView.backgroundColor = [UIColor yellowColor];
    self.iconImageView.layer.borderWidth = 1;
    self.iconImageView.layer.cornerRadius = 25;
    self.iconImageView.layer.masksToBounds = YES;
    self.iconImageView.layer.borderColor = [UIColor clearColor].CGColor;
    [self.contentView addSubview:self.iconImageView];
    
    
    self.nickNameLabel = [[UILabel alloc] init];
    self.nickNameLabel.textColor = [UIColor colorWithRed:0.057 green:0.5163 blue:0.9031 alpha:1.0];
    self.nickNameLabel.font = [UIFont systemFontOfSize:13.];
    [self.contentView addSubview:self.nickNameLabel];
    
    self.commentTimeLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.commentTimeLabel];
    self.commentTimeLabel.textColor = [UIColor lightGrayColor];
    self.commentTimeLabel.font = [UIFont systemFontOfSize:12.];
    
    
    self.contentaLabel = [[UILabel alloc] init];
    self.contentaLabel.backgroundColor = [UIColor colorWithRed:0.9211 green:0.921 blue:0.9211 alpha:0.5];
    self.contentaLabel.layer.borderWidth = 1;
    self.contentaLabel.layer.cornerRadius = 5;
    self.contentaLabel.layer.borderColor = [UIColor clearColor].CGColor;
    self.contentaLabel.layer.masksToBounds = YES;
    self.contentaLabel.font = [UIFont systemFontOfSize:13.];
    self.contentaLabel.textAlignment = NSTextAlignmentLeft;
    self.contentaLabel.numberOfLines = 0;
    [self.contentaLabel sizeToFit];
    
    [self.contentView addSubview:self.contentaLabel];
    
}

- (void)setMsgModel:(ZGSmsgCommentListModel *)msgModel{
    if (_msgModel != msgModel) {
        _msgModel = msgModel;
    }
    
    self.nickNameLabel.text = msgModel.nickName;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:msgModel.icon] placeholderImage:nil];
    self.contentaLabel.text = msgModel.content;
    
    
    
    NSDate *lastDate = [NSDate dateWithTimeIntervalSince1970:[msgModel.commentTime integerValue] / 1000];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"YYYY-MM-dd hh:mm"];
    NSString *time = [df stringFromDate:lastDate];
    self.commentTimeLabel.text = time;
}


- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.iconImageView.frame = CGRectMake(10, 5, 50, 50);
    self.nickNameLabel.frame = CGRectMake(65, 10, 100, 15);
    self.contentaLabel.frame = CGRectMake(65, 30, 300, 40);
    self.commentTimeLabel.frame = CGRectMake(65, 80, 100, 10);
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
